package utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateCoverter {
    //static final修饰是常量。在定义时需要初始化
    private static final DateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyy-MM-dd");//用于解析请求参数
    private static final DateFormat DEFAULT_DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//同上
    private static final DateFormat TIMESTAMP_CHARSQUENCE_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");//用于生成订单编号

    public static Date parseDate(String sDate) throws ParseException {
        return DEFAULT_DATE_FORMAT.parse(sDate);
    }
    public static String formatDate(Date date){
        return DEFAULT_DATE_FORMAT.format(date);
    }
    public static Date parseDateTime(String sDate) throws ParseException {
        return DEFAULT_DATE_TIME_FORMAT.parse(sDate);
    }

    public static String formatDateTime(Date date){
        return DEFAULT_DATE_TIME_FORMAT.format(date);
    }

    public static Date parseTimeStamp(String sDate) throws ParseException {
        return TIMESTAMP_CHARSQUENCE_FORMAT.parse(sDate);
    }

    public static String formatTimeStamp(Date date){
        return TIMESTAMP_CHARSQUENCE_FORMAT.format(date);
    }
}
